//
//  YWSelectViewController.m
//  百布业务
//
//  Created by 陈炳桦 on 15/11/9.
//  Copyright © 2015年 陈炳桦. All rights reserved.
//

#import "YWSelectViewController.h"

@interface YWSelectViewController ()

@property (nonatomic,strong) NSArray *contentArray;

@end

@implementation YWSelectViewController

#pragma mark - 懒加载
- (NSArray *)contentArray{
    if (_contentArray == nil) {
        if (self.type == 0) {
            _contentArray = @[@"需求",@"下单",@"集中采购"];
        }else if (self.type == 1) {
            _contentArray = @[@"有",@"没有"];
        }else{
            _contentArray = @[@"能",@"不能"];
        }
    }
    
    return _contentArray;
}

- (instancetype)init{
    return [super initWithStyle:UITableViewStyleGrouped];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"选择内容";
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.contentArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *ID = @"ID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    cell.textLabel.text = self.contentArray[indexPath.row];
    
    return cell;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *content = self.contentArray[indexPath.row];
    NSString *object = [NSString stringWithFormat:@"%@/%zd",content,self.type];
    
    // 发送通知
    [[NSNotificationCenter defaultCenter] postNotificationName:@"YWSelectViewController" object:object userInfo:nil];
    
    [self.navigationController popViewControllerAnimated:YES];
}

@end
